package net.zhuike.novel.app.ui.utils;

import java.util.LinkedHashMap;

/**
 * 按照插入顺序排序的Map，当超出容量时，将最早插入的对象移除。
 *
 * @param <K>
 * @param <V>
 */
public class FIFOMap<K, V> extends LinkedHashMap<K, V> {
	private static final long serialVersionUID = 27034646516234314L;

	protected int maxSize;
	public FIFOMap(int maxSize) {
		super(maxSize, 0.75f, false);
		this.maxSize = maxSize;
	}
	
	@Override
	protected boolean removeEldestEntry(Entry<K, V> eldest) {
		return maxSize < size();
	}

	public void setCapacity(int size) {
		maxSize = size;
	}
	public int getCapacity() {
		return maxSize;
	}
}
